<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="fn1">点我</button>
        {{ msg }}
    </div>

    <div id="app2">
        <h3 id="h3">我是app2 -- {{ msg }}</h3>
        {{ msg }}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        new Vue({
            el: "#app2",
            // template: "<div><h2>我是template -- {{ msg }}</h2></div>",
            data: {
                msg: '你好'
            },
            computed: {
                comMsg () {
                    return this.msg + ",xxxx"
                }
            },
            methods: {
                fn1 () {

                    // console.log(this.data.msg) // 报错

                    // vue实例会在某个阶段自动把data中的数据和methods中的方法
                    // 全部挂载当前实例的最外层
                    console.log(this)
                    console.log(this.msg)
                    console.log(this.comMsg)
                }
            },
            beforeCreate() {
                console.log('beforeCreate', this.msg) // undefined
            },
            created () {
                console.log('created', this.msg) // 你好
            },
            // 渲染前
            beforeMount() {
                console.log(document.querySelector('#h3').innerText)
            },
            // 渲染后
            mounted () {
                console.log(document.querySelector('#h3').innerText)
            }
        }) //.$mount('#app')
    </script>
</body>
</html>